package 力扣热题100;

import java.util.List;
import java.util.Stack;

public class LeetCode11 {
    public static boolean isValid(String s) {
        Stack<Character>stack=new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            if(stack.empty()){
                stack.push(s.charAt(i));
                continue;
            }
            if(stack.peek()=='('&&s.charAt(i)==')'){
                stack.pop();
                continue;
            }
            if(stack.peek()=='['&&s.charAt(i)==']'){
                stack.pop();
                continue;
            }if(stack.peek()=='{'&&s.charAt(i)=='}'){
                stack.pop();
                continue;
            }
            stack.push(s.charAt(i));
        }
        if(stack.empty()){
            return true;
        }else {
            return false;
        }
    }

    public static void main(String[] args) {
        String s="()";
        isValid(s);
    }
}
